<?php
namespace App\Http\Controllers\Business;


use Illuminate\Support\Facades\Redis;

class PublicBusiness {
    public static function getLongitudeAndLatitude($address) {
        if (!$address) {
            return ['status' => 'failed', 'message' => '参数不对！'];
        }
        $address = str_replace('（','(', $address);
        $address = str_replace('）', '(', $address);
        $address = str_replace(' ', '', $address);
        $url = "http://restapi.amap.com/v3/geocode/geo?key=77095839e7a388d0a59f32ae121ea2f5&output=JSON&address=" . $address;
        $content = file_get_contents($url);
        $data = json_decode($content, true);
        if(isset($data['geocodes'])) {
            $location = $data['geocodes']['0']['location'];
            $info = explode(',', $location);
            $returnData = [
                'longitude' => $info['0'],
                'latitude' => $info['1']
            ];
            return ['status'=>'success', 'data'=>$returnData];
        } else {
            return ['status'=>'failed', 'message'=>'获取失败'];
        }
    }
}